function plotScalograms(tP,fP,cfsP,tV,fV,cfsV)
%plotScalograms - Rainfall and velocity scalogram plot
%
%   plotScalograms(tP,fP,cfsP,tV,fV,cfsV)
%
% This function plots the rainfall and velocity scalograms, where tP, fP 
% and cfsP are related to rainfall data and tV, fV and cfsV are related to 
% velocity ones. The scalograms are plotted on subplots. If tV, fV and cfsV
% are undefined or empty, only the rainfall scalogram is plotted.      

% G. Teza, 2020

if nargin < 6
    cfsV = [];
end

cmap = jet(128);

hF = figure('units','normalized','outerposition',[0 0 1 1]);

if ~isempty(cfsV)
    hP = subplot(2,1,1);
else
    hP = gca; 
end

% pcolor(tP,log2(fP),abs(cfsP)); shading interp;
pcolor(tP,fP,rescale(abs(cfsP))); shading interp;
hP.Colormap = cmap;
cl = colorbar;
cl.Label.String = 'magnitude';
axis tight
title(hP,sprintf('Rainfall scalogram - from %s to %s',...
    datestr(tP(1)),datestr(tP(end))));
xlabel('\ittime \rm(days)','FontSize',16);
ylabel('\itfrequency \rm(cpd)','FontSize',16);
set(gca,'FontSize',16); 
set(gca,'YScale', 'log');
datetick('x',19);

if ~isempty(cfsV)
    hV = subplot(2,1,1);
    pcolor(tV,log2(fV),rescale(abs(cfsV))); shading interp;
    hV.Colormap = cmap;
    cl = colorbar;
    cl.Label.String = 'magnitude';
    axis tight
    title(hV,sprintf('Velocity scalogram - from %s to %s',...
        datestr(tV(1)),datestr(tV(end))));
    xlabel('\ittime \rm(days)','FontSize',16);
    ylabel('log_2(\itfrequency\rm/cpd)','FontSize',16);
    set(gca,'FontSize',16); 
    set(gca,'YScale', 'log');
    datetick('x',19);
end